package com.google.code.lightsomy.section;

/**
 * Section holds info needed for package based modularity.
 * 
 * @author Viktoras Agejevas
 *
 */
public class Section {

	private String name;
	
	private String packageName;

	
	public Section(String name, String packageName) {
		setName(name);
		setPackageName(packageName);
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		if (name == null) {
			throw new NullPointerException("Name can't be null");
		}
		this.name = name;
	}

	public String getPackageName() {
		return packageName;
	}

	public void setPackageName(String packageName) {
		if (packageName == null) {
			throw new NullPointerException("Package name can't be null");
		}
		this.packageName = packageName;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result
				+ ((packageName == null) ? 0 : packageName.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		
		Section other = (Section) obj;
		
		return (name == null ? other.getName() == null 
							 : name.equals(other.getName())) &&
			   (packageName == null ? other.getPackageName() == null 
					   				: packageName.equals(other.getPackageName()));
	}

	@Override
	public String toString() {
		return String.format("Section [name: %s, package: %s]", name, packageName);
	}
	
}
